import axios from 'axios';
import type { Version } from '../types/global';

export interface VersionCreateRequest {
  baseVer: string | null;
  newVer: string;
  description: string;
}

export const createVersion = async (data: VersionCreateRequest): Promise<Version> => {
  const response = await axios.post('/api/versions', data);
  console.log('创建版本API响应:', {
    url: response.config.url,
    status: response.status,
    data: response.data
  });
  return response.data;
};

export const publishVersion = async (versionId: string): Promise<Version> => {
  const response = await axios.put(`/api/versions/${versionId}/publish`);
  console.log('发布版本API响应:', {
    url: response.config.url,
    status: response.status,
    data: response.data
  });
  return response.data;
};

export const getVersion = async (versionId: string): Promise<Version> => {
  const response = await axios.get(`/api/versions/${versionId}`);
  console.log('获取版本API响应:', {
    url: response.config.url,
    status: response.status,
    data: response.data
  });
  return response.data;
};

export const getAllVersions = async (): Promise<Version[]> => {
  const response = await axios.get('/api/versions');
  console.log('获取所有版本API响应:', {
    url: response.config.url,
    status: response.status,
    data: response.data
  });
  return response.data;
};
